package cn.dglydrpy.fundmanagement.controller;

import cn.dglydrpy.fundmanagement.service.ITaxCalculationService;
import cn.dglydrpy.fundmanagement.service.dto.TaxCalculationDto;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/taxCalculations")
public class TaxCalculationController {

    @Autowired
    private ITaxCalculationService taxCalculationService;

    @PostMapping("/addTaxCalculation")
    public void addTaxCalculation(@RequestBody TaxCalculationDto taxCalculationDto) {
        taxCalculationService.saveTaxCalculation(taxCalculationDto);
    }

    @PostMapping("/updateTaxCalculation")
    public void updateTaxCalculation(@RequestBody TaxCalculationDto taxCalculationDto) {
        taxCalculationService.updateTaxCalculation(taxCalculationDto);
    }

    @PostMapping("/deleteTaxCalculation/{id}")
    public void deleteTaxCalculation(@PathVariable Long id) {
        taxCalculationService.deleteTaxCalculation(id);
    }

    @GetMapping("/{id}")
    public TaxCalculationDto getTaxCalculationById(@PathVariable Long id) {
        return taxCalculationService.getTaxCalculationById(id);
    }

    @GetMapping("/getTaxCalculationsByConditions")
    public Page<TaxCalculationDto> getTaxCalculationsByConditions(
            @RequestParam String fundCode,
            @RequestParam String portfolioId,
            @RequestParam int pageNo,
            @RequestParam int pageSize) {
        return taxCalculationService.getTaxCalculationsByConditions(fundCode, portfolioId, pageNo, pageSize);
    }

    @GetMapping("/getAllTaxCalculations")
    public List<TaxCalculationDto> getAllTaxCalculations() {
        return taxCalculationService.getAllTaxCalculations();
    }

    @PostMapping("/calculateTaxForTransaction")
    public void calculateTaxForTransaction(@RequestParam Long transactionId) {
        taxCalculationService.calculateTaxForTransaction(transactionId);
    }

    @PostMapping("/calculateTaxForFund")
    public void calculateTaxForFund(@RequestParam String fundCode) {
        taxCalculationService.calculateTaxForFund(fundCode);
    }

    @PostMapping("/calculateTaxForPortfolio")
    public void calculateTaxForPortfolio(@RequestParam Long portfolioId) {
        taxCalculationService.calculateTaxForPortfolio(portfolioId);
    }
}